﻿using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using System.Collections.Generic;

namespace Baosight.ZNH.ZMCS.UI
{
    public partial class ZMCS80 : EFViewCmes
    {
        private EFTreeItem item;//记录选中的树节点

        public ZMCS80()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ZMCS80_Loaded);
        }

        /// <summary>
        /// 初始化树
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZMCS80_Loaded(object sender, RoutedEventArgs e)
        {
            this.projectModelTree.Refresh();
        }


        /// <summary>
        /// 第一次进入页面时选中树的根节点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void projectModelTree_ItemPrepared(object sender, Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs e)
        {
            if (e.PreparedItem == null)
            {
                return;
            }
            EFTreeItem treeItem = e.PreparedItem as EFTreeItem;
            if (treeItem.Level == 0 && treeItem.Index == 0)
            {
                this.projectModelTree.SelectedItem = treeItem;//选中
                treeItem.ExpandItem();//展开
            }
        }

        /// <summary>
        /// 选中节点时
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void projectModelTree_Selected(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            item = this.projectModelTree.SelectedItems[0] as EFTreeItem;
            string parentTypes = item.ItemObject.GetType().GetProperty("parentTypes").GetValue(item.ItemObject, null) as string;
            string childTypes = item.ItemObject.GetType().GetProperty("childTypes").GetValue(item.ItemObject, null) as string;
            string isLeaf = (item.IsLeaf == true) ? "1" : "0";

            Dictionary<string, string> args = new Dictionary<string, string>();
            args.Add("parentTypes", parentTypes);

            if (item.IsLeaf)
            {
                args.Add("childTypes", childTypes);
            }
            this.container.LoadView<EFCustomViewContainerPanel>("ZMCS81", args);
        }
    }
}
